import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param indexArray int整型二维数组 
     * @param n int整型 
     * @return int整型
     */
    public int maxConnectedTrianglesSize (int[][] indexArray, int n) {
        // write code here
        // [[0, 1, 2], [0, 2, 3], [4, 5, 6], [2, 3, 4]],4
        Map<StringBuilder, Integer> map = new HashMap<>();
        int ret = 1;
        for (int i = 0; i < n; i++) {
            StringBuilder s1 = new StringBuilder();
            s1.append(indexArray[i][0]);
            s1.append(indexArray[i][1]);
            map.put(s1, map.getOrDefault(String.valueOf(s1), 0) + 1);
            StringBuilder s2 = new StringBuilder();
            s2.append(indexArray[i][0]);
            s2.append(indexArray[i][2]);
            map.put(s2, map.getOrDefault(String.valueOf(s2), 0) + 1);
            StringBuilder s3 = new StringBuilder();
            s3.append(indexArray[i][1]);
            s3.append(indexArray[i][2]);
            map.put(s3, map.getOrDefault(String.valueOf(s3), 0) + 1);
            if (map.get(s1) > 1 && map.get(s2) > 1 || map.get(s1) > 1 && map.get(s3) > 0 || map.get(s2) > 1 && map.get(s3) > 1) ret++;
        }
        return ret;
    }
}